package ah.file;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

import mail.MailTest;

public class FileChannelT {

	public static void readFile(String fName) throws Exception {
		BufferedReader br = new BufferedReader(new FileReader(fName));
		BufferedWriter bw = new BufferedWriter(new FileWriter("F:\\www.csdn.net2.sql"));
		String str = br.readLine();
		MailTest mailTest = new MailTest("smtp.qq.com");
		while(str != null) {
			if (str.toLowerCase().contains("qq.com")) {
				String[] arr = str.split(" # ");
				bw.write(arr[2].substring(0, arr[2].indexOf("@")) + " " + arr[1] + "\n");
				//mailTest.sendMail(arr[2].substring(0, arr[2].indexOf("@")), arr[1]);
			}
			str = br.readLine();
		}
		br.close();
		bw.close();
	}

	public static void sendMail() throws Exception {
		BufferedReader br = new BufferedReader(new FileReader("F:\\www.csdn.net2.sql"));
		String str = br.readLine();
		MailTest mailTest = new MailTest("smtp.qq.com");
		int i = 0;
		while(str != null) {
			try {
				String[] arr = str.split(" ");
				mailTest.sendMail(arr[0], arr[1]);
			} catch (Exception e) {
				e.printStackTrace();
			}
			str = br.readLine();
		}
		br.close();
	}
	
	// 测试主方法
	public static void main(String[] args) throws Exception {
		//readFile("F:\\www.csdn.net.sql");
		sendMail();
	}

}
